<?php

/**
 * This is the model class for table "fitz_store".
 *
 * The followings are the available columns in table 'fitz_store':
 * @property integer $id
 * @property string $code
 * @property string $name
 * @property string $directDial
 * @property string $contactName
 * @property string $address
 * @property string $suburb
 * @property string $city
 * @property string $state
 * @property string $postcode
 * @property string $contactPhone
 * @property string $contactFax
 * @property string $contactMobile
 * @property string $contactEmail
 * @property string $manager
 * @property string $managerEmail
 * @property string $administrator
 */
class Store extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Store the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'fitz_store';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('code, name, contactName, address, suburb, city, state, postcode, contactPhone, manager', 'required'),
			array('code, directDial, state, postcode, contactPhone, contactFax, contactMobile, contactEmail', 'length', 'max'=>45),
			array('name, contactName, address, manager, managerEmail, administrator', 'length', 'max'=>255),
			array('suburb, city', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, code, name, directDial, contactName, address, suburb, city, state, postcode, contactPhone, contactFax, contactMobile, contactEmail, manager, managerEmail, administrator', 'safe', 'on'=>'search'),
			
			// The following rule is used by insert and update.
			array('contactEmail, managerEmail', 'email', 'on'=>'insert, update'),
			
			// Set default value for empty input of some feilds.
			array('directDial, contactMobile, contactEmail, managerEmail, contactFax, administrator',
				'default','value'=>'','setOnEmpty'=>true,'on'=>'insert,update'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'code' => 'Store Code',
			'name' => 'Store Name',
			'directDial' => 'Direct Dial',
			'contactName' => 'Contact Name',
			'address' => 'Address',
			'suburb' => 'Suburb',
			'city' => 'City',
			'state' => 'State',
			'postcode' => 'Postcode',
			'contactPhone' => 'Store Phone',
			'contactFax' => 'Store Fax',
			'contactMobile' => 'Contact Mobile',
			'contactEmail' => 'Store Email',
			'manager' => 'Manager',
			'managerEmail' => 'Manager Email',
			'administrator' => 'Administrator',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('code',$this->code,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('directDial',$this->directDial,true);
		$criteria->compare('contactName',$this->contactName,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('suburb',$this->suburb,true);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('state',$this->state,true);
		$criteria->compare('postcode',$this->postcode,true);
		$criteria->compare('contactPhone',$this->contactPhone,true);
		$criteria->compare('contactFax',$this->contactFax,true);
		$criteria->compare('contactMobile',$this->contactMobile,true);
		$criteria->compare('contactEmail',$this->contactEmail,true);
		$criteria->compare('manager',$this->manager,true);
		$criteria->compare('managerEmail',$this->managerEmail,true);
		$criteria->compare('administrator',$this->administrator,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}